/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import OBJECT.ChiTietTuyenDuong;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Ngoc Anh
 */
public class ChiTietTuyenDuongDAO {
     private Connect connect=null;

    public ChiTietTuyenDuongDAO(String User ,String Pass,String port,String DataBase,String Host) {
         connect =new Connect( User , Pass, port, DataBase, Host);
    }
    
      public CallableStatement DanhSachGaCua1TuyenDuong(int matd)
    {
        Connection conn=connect.GetConnect();
        ResultSet result=null;
        CallableStatement cals=null;
        try {
            
             cals=conn.prepareCall("{call sp_DanhSachGaDen1TuyenDuong(?)}");
              cals.setInt(1, matd);
              return cals;
        } catch (SQLException ex) {
          ;
            
        }finally{
            // CloseConnect();
         }   
       return cals;
    }
    
   
    public List<ChiTietTuyenDuong> DanhSachGaCua2TuyenDuong(int matd)
    {
         Connection conn=connect.GetConnect();
         ResultSet result=null;
         CallableStatement cals=null;
         ChiTietTuyenDuong cttd=null;
         List<ChiTietTuyenDuong> list = new ArrayList<ChiTietTuyenDuong>();                
         
         try{
                 cals=conn.prepareCall("{call sp_DanhSachGaDen1TuyenDuong(?)}");                
                 cals.setInt(1, matd);
                 result  =cals.executeQuery();
                 while(result.next())
                 {
                     cttd = new ChiTietTuyenDuong();
                     cttd.setMaCTTuyenDuong(result.getInt("MaCT_TuyenDuong"));
                     cttd.setMaTuyenDuong(result.getInt("Ma_TuyenDuong"));
                     cttd.setTenGaDen(result.getString("TenGaDen"));
                     cttd.setSoKM(result.getFloat("SoKM"));
                     cttd.setTinhTrang(result.getString("TinhTrangTD"));
                     list.add(cttd);
                 }
                 result.close();
                 
         }catch(Exception exc)
         {
            
             return null;
             
         }
         finally{
             CloseConnect();
         }     
         return list;
}
    
   
     public void CloseConnect()
      {
          try
          {
          connect.Close();
          }catch(Exception e)
          {
              ;
          }
      } 
}
